package com.coin900.coin.server.sbi.ctrl;

import com.coin900.coin.base.AjaxResponse;
import com.coin900.coin.persist.sbi.SbiCityVO;
import com.coin900.coin.persist.sbi.SbiProvinceVO;
import com.coin900.coin.server.BaseController;
import com.coin900.coin.service.sbi.ISbiCityService;
import com.coin900.coin.service.sbi.ISbiProvinceService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shui
 * @create 2017-12-11
 **/
@Controller
public class SbiCtrl extends BaseController {

    private static final Log logger = LogFactory.getLog(BaseController.class);

    @RequestMapping(value = "/sbi/city", method = RequestMethod.GET)
    public ModelAndView cityList(@RequestParam(required = false) Long provinceId, HttpServletRequest request) {
        AjaxResponse response = super.buildAjaxResponse(request);
        Map<String, Object> params = new HashMap<>();
        params.put("dataStatus", 1);
        params.put("provinceId", provinceId);
        List<SbiCityVO> sbiCityVOS = this.cityService.loadSbiCity(params);
        response.addModels(sbiCityVOS);
        return response.getMav();
    }

    @RequestMapping(value = "/sbi/province", method = RequestMethod.GET)
    public ModelAndView provinceList(HttpServletRequest request) {
        AjaxResponse response = super.buildAjaxResponse(request);
        Map<String, Object> params = new HashMap<>();
        params.put("dataStatus", 1);
        List<SbiProvinceVO> sbiProvinceVOS = this.provinceService.loadSbiProvince(params);
        response.addModels(sbiProvinceVOS);
        return response.getMav();
    }

    @Override
    protected String getJsonPath() {
        String name = this.getClass().getSimpleName();
        name = name.replace(".", "/");
        return "/com/coin900/coin/server/sbi/json/" + name + ".json";
    }

    @Autowired
    private ISbiCityService cityService;
    @Autowired
    private ISbiProvinceService provinceService;
}
